#!/usr/bin/env python
#
# Launch a game.
# For Windows: python launch <name>

import sys

def run_game(args):
    if len(args)<2:
        print >>sys.stderr, 'No game name specified.'
        sys.exit(2)

    gname = args[1]     # game name to run

    # Add local libs to Python path.
    sys.path = ['libs', 'games/'+args[1]] + sys.path

    try:
        gmod = __import__(gname)
    except ImportError:
        print >>sys.stderr, 'Gamelab: Game "%s" not found' % gname
        sys.exit(2)
    except OSError:
        from gamelab import checkenv
        checkenv.check_env()
        sys.exit(1)

    # Start the game with any extra arguments passed.
    gmod.main(args[2:])

run_game(sys.argv)
